#ifndef CONNECT_MYSQL_H
#define CONNECT_MYSQL_H

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <mysql.h>
#include "clnt_connection.h"

#define MYSQL_HOST "127.0.0.1"
#define MYSQL_USER "root"
#define MYSQL_PASSWD "1q2w3e"
#define MYSQL_DATABASE "guru"

#define NAME "name"
#define PASSWORD "password"

#define SEARCH_QUERY "SELECT %s FROM customers WHERE %s LIKE '%s'"
#define INSERT_QUERY "INSERT INTO customers VALUES ('%s', '%s')"
#define APP_NAME_QUERY "INSERT INTO applist SET name = '%s'"

#define SEARCH_APP_NAME "SELECT NAME FROM applist WHERE NAME LIKE '%s'"
#define SEARCH_APP_ID "SELECT applist_id, name FROM applist WHERE name LIKE '%s'"

#define APP_PATH_IP_QUERY "INSERT INTO applistoption (applist_id, ip, apppath) VALUES (%s, '%s', '"
#define ICON_LOAD_QUERY "UPDATE applist SET iconimage = load_file('/icons/%s.bmp') WHERE name = '%s'"

#define APPLISTOPTION_DELETE "DELETE FROM applistoption WHERE ip='%s'"
#define APPLIST_DELETE "DELETE FROM applist WHERE applist_ip = %s"
#define SEARCH_APPLISTOPTION "SELECT applist_id, ip from applistoption WHERE ip LIKE '%s'"
#define SEARCH_APPLIST_ID "SELECT applist_id FROM applistoption WHERE applist_id LIKE '%s'"

static MYSQL *conn, mysql;
static MYSQL_RES *sql_result;
static MYSQL_ROW sql_row;
static char sqlbuf[160];  

void connect_mysql(void);
void mysql_idcheck(USER* user);
void mysql_joincheck(USER* user);
void mysql_logincheck(USER* user);
void mysql_app_list(APP* app, char* ip);
char* strmov(char* dest, const char* src);
void mysql_icon_load(char* name);
void mysql_server_stop(char *ip);


#endif
